@echo off
::---------------edit to modify start configuration----
set mmap=\2012\final\Eindhoven1
::set mmap=Eindhoven1
set mapDir=..\maps\Kobe1\map
set cfgDir=..\maps\Kobe1\config
set enableViewer=true
set waitTime=10
set enableKillAll=true
::---------------edit to modify start configuration----
echo mapDir %mapDir%%*
echo cfgDir %cfgDir%%*


:MakeClasspath
	setlocal EnableDelayedExpansion
	set CP=..\supplement;
	for /f "tokens=*" %%i in ('dir ..\lib /b'); do set CP=!CP!..\lib\%%i;
	for /f "tokens=*" %%i in ('dir ..\jars /b'); do set CP=!CP!..\jars\%%i;
	::goto :eof

:StartKernel
echo CP !CP!
::echo %*
start "kernel" java -Xmx1024m -cp !CP! kernel.StartKernel -c %cfgDir%\kernel.cfg --nomenu --gis.map.dir=%mapDir%

echo continue start sims? Make sure that kernel has started.

ver | findstr "5.1." > nul  && ping 127.0.0.1 -n %waitTime% >nul ||  timeout /t %waitTime%
::for xp or lower
::ping 127.0.0.1 -n %waitTime% >nul
::for win7 or vista
::timeout /t %waitTime%

:StartSims
	echo StartSims
	start "misc" java -Xmx256m -cp !CP! rescuecore2.LaunchComponents misc.MiscSimulator -c %cfgDir%\misc.cfg 
	start "traffic" java -Xmx256m -cp !CP! rescuecore2.LaunchComponents traffic3.simulator.TrafficSimulator -c %cfgDir%\traffic3.cfg 
	start "fire" java -Xmx256m -cp !CP! rescuecore2.LaunchComponents firesimulator.FireSimulatorWrapper -c %cfgDir%\resq-fire.cfg 
	start "ignition" java -Xmx256m -cp !CP! rescuecore2.LaunchComponents ignition.IgnitionSimulator -c %cfgDir%\ignition.cfg 
	start "collapse" java -Xmx256m -cp !CP! rescuecore2.LaunchComponents collapse.CollapseSimulator -c %cfgDir%\collapse.cfg 
	start "clear" java -Xmx256m -cp !CP! rescuecore2.LaunchComponents clear.ClearSimulator -c %cfgDir%\clear.cfg
	start "civilian" java -Xmx1024m -cp !CP! rescuecore2.LaunchComponents sample.SampleCivilian*n -c %cfgDir%\civilian.cfg

:StartViewer
	if "%enableViewer%"=="true" start "viewer" java -Xmx256m -cp !CP! rescuecore2.LaunchComponents sample.SampleViewer -c config/viewer.cfg --viewer.maximise=true -h 127.0.0.1
	
if not "%enableKillAll%" == "true" goto :eof

echo press any key to kill kernel and sims
pause

:KillAll
	echo KillAll
	taskkill /f /im java.exe
goto :eof

:PrintUsage
	echo USAGE: start.bat map [--nomenu] [--autorun]
	echo For Example: start.bat test --autorun --nomenu
	random.seed=1
goto :eof